﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AlphaShowHideUI : ShowHideObject
{

    protected ZUIAnimTools MZuiAnimTools;

    protected virtual void Awake()
    {
        CheckUIAnimNull();

        var rectTransform = GetComponent<RectTransform>();
        ZUIAnimTools.GetImgTxtAlpha(rectTransform, out imgAlphas, out txtAlphas, out rawAlphas,out tmptxtAlphas);
    }

    void CheckUIAnimNull()
    {
        if (MZuiAnimTools == null) MZuiAnimTools = GetComponent<ZUIAnimTools>();
        if (MZuiAnimTools == null) MZuiAnimTools = gameObject.AddComponent<ZUIAnimTools>();

    }
    List<float> imgAlphas;
    List<float> txtAlphas;
    List<float> rawAlphas;
    List<float> tmptxtAlphas;
    protected override void _Show(System.Action onEnd)
    {
        CheckUIAnimNull();
        
        var trans = GetComponent<RectTransform>();
        MZuiAnimTools.SetImgTxtAlpha(trans, 0);

        if (gameObject.activeInHierarchy)
            MZuiAnimTools.UIAlpha(trans, imgAlphas, txtAlphas, rawAlphas,tmptxtAlphas,this.showAnimTime, onEnd, ZUIAnimTools.EaseType.Curve);
    }

    protected override  void _Hide(System.Action onEnd)
    {
        CheckUIAnimNull();

        if (gameObject.activeInHierarchy)
        {
            MZuiAnimTools.UIAlpha(GetComponent<RectTransform>(), 0, hideAnimTime, onEnd, ZUIAnimTools.EaseType.Curve);
        }
    }

    public void SetAlpha(float alpha)
    {
        MZuiAnimTools.SetImgTxtAlpha(GetComponent<RectTransform>(), alpha);
    }

}